<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script type="application/javascript" src="../../../../jquery/jquery-1.12.0-uncompressed.js"></script>
<!--<script type="application/javascript" src="../plugin4object.js"></script>-->
<script type="application/javascript" >
    //插件编写
    ;(function($){
        $.fn.extend({
            "color" : function(value) {
                if (value == undefined) {
                    return this.css("color");
                } else {
                    return this.css("color", value);
                }
                //return this.css("color", value);
                // 经过测试，if(value == undefined)不可缺少；单纯的this.css("color", value);无法达到所需效果
                // 当value == undefined的时候， $("div").color() 返回的是[object Object]
            }
        });
    })(jQuery);

    //插件应用
    $(function(){
        alert($("div").color() + "\n 返回字符串，证明此插件可用。");
        alert($("div").color("red") + "\n 返回object，证明得到的是jQuery对象。");
    })

</script>

<div class="a">red</div>
<div style="color: blue">blue</div>
<div style="color: green">green</div>
<div style="color: yellow">yellow</div>
</body>
</html>